package com.lagou.rabbitmq.demo.homework.service;


import com.lagou.rabbitmq.demo.homework.entity.OrderStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

@Service
public class RedisService {

    public static String order_key = "order-key";

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    public void saveOrder(String orderId){
        redisTemplate.opsForValue().set(order_key, orderId);
    }

    public void cannelOrder(String orderId){
        redisTemplate.delete(order_key);
    }

    public void payOrderSuc(String orderId){
        redisTemplate.opsForValue().set(order_key, orderId + ":" + OrderStatus.PAYED);
    }

    public void unPayOrder(String orderId){
        redisTemplate.opsForValue().set(order_key, orderId + ":" + OrderStatus.TO_BE_PAYED);
    }

    public void canceledPayOrder(String orderId){
        redisTemplate.opsForValue().set(order_key, orderId + ":" + OrderStatus.CANCELED);
    }
}
